import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:hktk_app/dao/free.dart';
import 'package:hktk_app/pages/course/free_video.dart';

// 列举部分视频资料
class FreeSource extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => _FreeSourceState();
}

class _FreeSourceState extends State<FreeSource> {
  late PageController _controller;
  late List<dynamic> _freeVideos = [];
  late List<dynamic> _freeMaterial = [];

  @override
  void initState() {
    //   initState
    super.initState();
    _controller = PageController(initialPage: 0);
    Future.wait([
      // 获取免费视频
      Free.getFreeVideo(type: "video"),
      // 获取免费资料
      Free.getFreeVideo(type: "material")
    ]).then((value) {
      if (mounted) {
        setState(() {
          _freeVideos = value[0];
          _freeMaterial = value[1];
        });
      }
    }).catchError((error) {});
  }

  @override
  void dispose() {
    //   dispose
    super.dispose();
    _controller.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text('免费资源'),
        ),
        body: SafeArea(
          child: PageView(
            controller: _controller,
            physics: const NeverScrollableScrollPhysics(), // 禁用左右滚动
            children: <Widget>[
              // ListView(children: <Widget>[
              //   ListTile(
              //     title: Text('1. 极客时间'),
              //     subtitle: Text('https://time.geekbang.org/'),
              //   ),
              //   ListTile(
              //     title: Text('2. 极客学院'),
              //     subtitle: Text('https://www.imooc.com/'),
              //   ),
              //
              // ])
              Column(
                children: [
                  for (var item in _freeVideos)
                    Container(
                      width: 1.sw,
                      margin: EdgeInsets.all(10),
                      padding: EdgeInsets.all(5),
                      decoration: BoxDecoration(
                        borderRadius: BorderRadius.circular(10),
                        color: Colors.white,
                      ),
                      child: InkWell(
                        onTap: () {
                          //   点击跳转播放视频
                          // Navigator.push(
                          //     context,
                          //     MaterialPageRoute(
                          //         builder: (context) => FreeVideo(
                          //             topChapterId: item["id"],
                          //             columnId: columnId,
                          //             aliyunVideoId: aliyunVideoId,
                          //             videoTitle: videoTitle)));
                        },
                        child: Text(
                          item["name"],
                          style: TextStyle(fontSize: 20),
                        ),
                      ),
                    )
                ],
              ),
              Column(
                children: [
                  for (var item in _freeMaterial)
                    InkWell(
                      onTap: () {
                        //   点击跳转
                      },
                      child: Text(""),
                    )
                ],
              ),
            ],
          ),
        ),
        bottomNavigationBar: BottomNavigationBar(
            onTap: (index) {
              _controller.jumpToPage(index);
            },
            items: [
              BottomNavigationBarItem(
                icon: Icon(Icons.video_camera_front),
                label: '视频',
              ),
              BottomNavigationBarItem(
                icon: Icon(Icons.file_present),
                label: '资料',
              ),
            ]));
  }
}
